package com.onLineCar.amap.controller;



import com.onLineCar.amap.domain.AMapAddressData;
import com.onLineCar.amap.domain.AMapRouteData;

import com.onLineCar.amap.domain.RouteReq;
import com.onLineCar.amap.service.AMapService;
import com.onLineCar.common.core.domain.Result;
import com.onLineCar.common.core.web.controller.BaseController;
import com.onLineCar.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.bind.annotation.*;


/**
 * 地图Controller
 *
 * @author onLineCar
 * @date 2023-12-12
 */
@RestController
@RequestMapping("/amap")
public class AMapController extends BaseController {

    @Autowired
    private AMapService aMapService;


    /**
     * 获取路线
     * @param routeReq
     * @return
     */

//    @RequiresPermissions("amap:operation")
    @PostMapping("/getRoute")
    public Result<AMapRouteData> getRoute(@RequestBody RouteReq routeReq) {
        AMapRouteData route = aMapService.getRoute(routeReq.getOrigin(), routeReq.getDestination());
        return Result.success(route);
    }

    /**
     * 根据经纬度获取地址
     * @param location
     * @return
     */
//    @RequiresPermissions("amap:operation")
    @PostMapping("/getAddressByLocation/{location}")
    public Result<AMapAddressData> getAddressByLocation(@PathVariable String location) {
        AMapAddressData address = aMapService.getAddressByLocation(location);
        return Result.success(address);
    }

}
